package com.yao.club.service.impl;

import com.yao.club.entity.UserEntity;
import com.yao.club.entity.dto.PostsTipOff;
import com.yao.club.entity.dto.PostsTipOffRecord;
import com.yao.club.entity.request.PostsTipOffRequestEntity;
import com.yao.club.entity.result.ResponseEntity;
import com.yao.club.mapper.UserMapper;
import com.yao.club.reposittory.PostsTipOffRecordRepository;
import com.yao.club.reposittory.PostsTipOffRepository;
import com.yao.club.service.PostsTipOffService;
import com.yao.club.utils.ResponseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PostsTipOffServiceImpl  implements PostsTipOffService {

    @Autowired
    PostsTipOffRepository postsTipOffRepository;
    @Autowired
    PostsTipOffRecordRepository postsTipOffRecordRepository;
    @Resource
    UserMapper userMapper;
    /**
     * 举报信息列表
     * @return
     */
    @Override
    public ResponseEntity<List<PostsTipOff>> list(){
        List<PostsTipOff> list = postsTipOffRepository.findAll();
        return ResponseUtils.success(list);
    }

    /**
     * 举报帖子
     * @param clubTipOffRequestEntity
     * @param username
     * @return
     */
    @Override
    public ResponseEntity<Boolean> save(PostsTipOffRequestEntity clubTipOffRequestEntity, String username) {
        UserEntity userEntity = userMapper.select(username);
        PostsTipOffRecord postsTipOffRecord = new PostsTipOffRecord();
        postsTipOffRecord.setPostId(Long.parseLong(clubTipOffRequestEntity.postsId));
        postsTipOffRecord.setUserId(userEntity.member_id);
        postsTipOffRecord.setTipOffType(Integer.parseInt(clubTipOffRequestEntity.tipOffType));
        postsTipOffRecordRepository.save(postsTipOffRecord);
        return ResponseUtils.success(true);
    }
}
